<?php
	include 'inc/conn.php';

	$p_new_lines = array("\r\n", "\n", "\r","\r\n", "<p>","</p>","<br>","</br>","<br/>","<br />");
	$p_change_line_in_excel_cell = '<br style="mso-data-placement:same-cell;" />';

	header ("Content-type:application/vnd.ms-excel");
	header ("Content-Disposition:filename=HW_Change_Table.xls");
	echo "<table border='1'>";
	echo "<tr><td align='center' colspan='10'><font size='4'>HW变更记录表</font></td></tr>";
	echo "<tr style='font-size: 20px;height: 40px;'>";
	echo " <td align='center' bgcolor='#538dd5'><font color='ffffff'>编号</font></td>"; 
	echo " <td align='center' bgcolor='#538dd5'><font color='ffffff'>主板名称</font></td>"; 
	echo " <td align='center' bgcolor='#538dd5'><font color='ffffff'>主板版号</font></td>";
	echo " <td align='center' bgcolor='#538dd5'><font color='ffffff'>变更原因</font></td>";
	echo " <td align='center' bgcolor='#538dd5'><font color='ffffff'>变更位置</font></td>";
	echo " <td align='center' bgcolor='#538dd5'><font color='ffffff'>变更日期</font></td>"; 
	echo " <td align='center' bgcolor='#538dd5'><font color='ffffff'>管控人员</font></td>";
	echo " <td align='center' bgcolor='#538dd5'><font color='ffffff'>增加时间</font></td>";
	echo " <td align='center' bgcolor='#538dd5'><font color='ffffff'>更新时间</font></td>";
	echo " <td align='center' bgcolor='#538dd5'><font color='ffffff'>备注说明</font></td>";
	echo "</tr>";

	$db = new mysql();
	$sql = "select * from hw_change ORDER BY add_date DESC";
	$db->query($sql);
	$num = $db->db_num_rows();
	if ($num == 0)
		echo "No data was found!";

	for($i=0; $i<$num; $i++){
		$row = $db->fetch_assoc();
		$j=$i+1;
		echo "<tr><td align='center'>$j</td><td align='center'>".
			htmlspecialchars_decode($row['MB_NAME'])."</td><td align='center'> ".
			htmlspecialchars_decode($row['MB_VER'])."</td><td align='center'> ".
			str_replace($p_new_lines, $p_change_line_in_excel_cell, htmlspecialchars_decode($row['MB_REASON']))."</td><td align='center'>".
			str_replace($p_new_lines, $p_change_line_in_excel_cell, htmlspecialchars_decode($row['MB_LOCATION']))."</td><td align='center'>".
			substr(htmlspecialchars_decode($row['MB_CHANGEDATE']),0,10)."</td><td align='center'>".
			htmlspecialchars_decode($row['OWNER'])."</td><td align='center'>".
			substr(htmlspecialchars_decode($row['add_date']),0,10)."</td><td align='center'>".
			substr(htmlspecialchars_decode($row['up_date']),0,10)."</td><td align='center'>".
			str_replace($p_new_lines, $p_change_line_in_excel_cell, htmlspecialchars_decode($row['REMARK']))."</td></tr>";
	}
	echo "</table>";
	$db->close();
?>